package com.tanhua.server.service;

import com.tanhua.dubbo.api.UserLocationApi;
import com.tanhua.model.vo.ErrorResult;
import com.tanhua.server.exception.BusinessException;
import com.tanhua.server.interceptor.ThreadLocalUtils;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.stereotype.Service;

@Service
public class BaiduService {

    @DubboReference
    private UserLocationApi userLocationApi;


    /**
     * 上报地理位置
     * @param longitude 经度
     * @param latitude  纬度
     * @param address
     */

    public void saveAndUpdateLocation(Double longitude, Double latitude, String address) {

        //1.调用api保存或更新用户的地理位置信息
        Long userId = ThreadLocalUtils.getUserId();
        Boolean result = userLocationApi.saveAndUpdateLocation(userId, longitude, latitude, address);
        //2.如果保存或更新失败抛出异常
        if(!result){
            throw new BusinessException(ErrorResult.error());
        }
    }



}
